package com.itheima.reggie.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.Mapper.CategoryMapper;
import com.itheima.reggie.Service.CategoryService;
import com.itheima.reggie.Service.DishService;
import com.itheima.reggie.Service.SetmealService;
import com.itheima.reggie.exception.CustomException;
import com.itheima.reggie.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private com.itheima.reggie.Service.DishService DishService;
    @Autowired
    private SetmealService setmealService;
    @Override
    public void removeId(Long ids) {
        QueryWrapper queryWrapper1=new QueryWrapper();
        queryWrapper1.eq("category_id",ids);
        int conut= DishService.count(queryWrapper1);
        if(conut>0)
        {
            throw  new CustomException("商品已关联删除失败,不能删除");
            //说明已经关联商品,抛出一个自定义异常
        }
        QueryWrapper queryWrapper2=new QueryWrapper();
        queryWrapper2.eq("category_id",ids);
        int count2=setmealService.count(queryWrapper1);
        if(count2>0)
        {
            throw  new CustomException("商品已关联删除失败,不能删除");
            //说明已经关联商品，抛出一个自定义异常
        }
        categoryService.removeById(ids);


    }
}
